﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WPFCouse.InkCanvas
{
    /// <summary>
    /// 看板的基本使用
    /// </summary>
    public partial class InkCanvasWindow : Window
    {
        public InkCanvasWindow()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 画笔记
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            this.inkCanvas.EditingMode = InkCanvasEditingMode.Ink;
            //var pints = this.inkCanvas.Strokes[0].StylusPoints;  // 可以获取到轨迹的所有点集合
        }

        /// <summary>
        /// 点删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.inkCanvas.EditingMode = InkCanvasEditingMode.EraseByPoint;
        }

        /// <summary>
        /// 线删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_2(object sender, RoutedEventArgs e)
        {
            this.inkCanvas.EditingMode = InkCanvasEditingMode.EraseByStroke;
        }

        /// <summary>
        /// 选中元素
        /// 允许用户选择保存在Children集合中的元素，要选择一个元素用户必须单机该元素或者拖动套索选择该元素，
        /// 一旦选择一个元素就可以移动该元素，改变其尺寸或将其删除
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_3(object sender, RoutedEventArgs e)
        {
            this.inkCanvas.EditingMode = InkCanvasEditingMode.Select;
        }

        /// <summary>
        /// 忽略鼠标和手写笔输入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_4(object sender, RoutedEventArgs e)
        {
            this.inkCanvas.EditingMode = InkCanvasEditingMode.None;
        }

        /// <summary>
        /// 笔记保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_8(object sender, RoutedEventArgs e)
        {
            // 笔迹的保存
            // 创建数据流（参数：路径、打开方式、读写）
            using FileStream fileStream = new FileStream("test.sk", FileMode.OpenOrCreate, FileAccess.ReadWrite);
            // 保存笔记
            this.inkCanvas.Strokes.Save(fileStream, false);
        }

        /// <summary>
        /// 笔记清空
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            // 清空笔记
            this.inkCanvas.Strokes.Clear();
        }

        /// <summary>
        /// 笔记加载
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click_6(object sender, RoutedEventArgs e)
        {
            // 创建数据流（参数：路径、打开文件、读取）
            using FileStream fileStream = new FileStream("test.sk", FileMode.Open, FileAccess.Read);
            // 添加笔记
            this.inkCanvas.Strokes.Add(new System.Windows.Ink.StrokeCollection(fileStream));
        }

        private void Button_Click_7(object sender, RoutedEventArgs e)
        {

        }
    }
}
